'use strict';

angular.module('afasApp')
  .controller('TemplateCtrl', ['$scope', '$routeParams', 'SubMenu', '$controller', function ($scope, $routeParams, SubMenu, $controller) {

    $scope.capitalize = function(word) {
      return word.charAt(0).toUpperCase() + word.slice(1);
    };

    $scope.activeLink = function(link) {
      if (link === $routeParams.feature) {
        return 'active';
      }
    };

    $scope.currentModule = SubMenu[$routeParams.module];

    $scope.moduleName = $routeParams.module;

    $scope.currentCtrl = $controller($scope.capitalize($routeParams.module)+'Ctrl',{$scope: $scope.$new()}).constructor;
    $scope.currentFile = 'views/modules/'+$routeParams.module+'.index.html';
    if ($routeParams.feature) {
      $scope.currentCtrl = $controller($scope.currentModule.subMenu[$routeParams.feature].controller,{$scope: $scope.$new()}).constructor;
      $scope.currentFile = $scope.currentModule.subMenu[$routeParams.feature].template;
    }


  }]).controller('TemplateMainCtrl', ['$scope', '$location', '$state', '$stateParams', 'ServicesLS', function ($scope, $location, $state, $stateParams, ServicesLS) {

    $scope.$state = $state;

    $scope.$watch(function() {
      $scope.activeModule = $location.path().split('/')[1];
    });

    // $scope.openDashboard = true;
    // $scope.openStudent = true;
    // $scope.openCourseClass = true;
    // $scope.openPT = true;
    // $scope.openMUT = true;
    // $scope.openTeacher = true;
    // $scope.openCashier = true;
    // $scope.openIALFProgram = true;
    // $scope.openStaff = true;
    // $scope.openStockMerchandise = true;
    $scope.openCourse = true;
    $scope.openRegistration = true;
    $scope.openPayment = true;
    $scope.openReport = true;
    $scope.openAdmin = true;
    // $scope.openCourse = true;
    $scope.openInventory = true;
    // $scope.openPayment = true;

    $scope.logMeOut = function(){
      ServicesLS.remove('_auth');
      ServicesLS.remove('_roles');
      ServicesLS.remove('_name');
      $state.transitionTo($state.current, $stateParams, {
        reload: true,
        inherit: false,
        notify: true
      });
      location.reload();
    };

  }]);
